<template>
  <div style="width:50%;margin:20px auto;">
      <h1 style="font-size:30px">添加分类</h1>
      <p>分类名称：<input type="text" v-model="cate_name"></p>
      <p>分类图片：<input type="file" id="img"></p>
      <p><input type="button" value="添加" @click="add_cate"></p>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            cate_name:'',
        }
    },
    methods:{
        add_cate(){
            let file=document.getElementById('img').files[0]
            const fdata=new FormData()
            fdata.append('cate_name',this.cate_name)
            fdata.append('cate_img',file)
            axios({
                url:'http://127.0.0.1:8000/app01/addcate/',
                method:'post',
                data:fdata
            }).then(resp=>{
                console.log(resp.data)
            })
        }
    },
    created() {

    }
}
</script>

<style>

</style>